using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Liberty.Domain.ServiceMemberManagement;

using Peradigm.Framework.Domain.Parties;
using Peradigm.Framework.UI.Web;

namespace Liberty.UI.Service.ServiceMemberManagement.Controls
{

    public partial class ServiceMemberDetailView : AbstractControl
    {
        #region Constants
        #endregion

        #region Event Handlers
        public override void UpdateView()
        {
            ServiceMember serviceMember = this.ServiceMember;

            this.lblServiceMemberRankAndName.Text = serviceMember.CanonicalName;

            DateTime bornOn = DateTime.Parse( serviceMember.BornOn.ToString() );
            this.lblServiceMemberDateOfBirth.Text = bornOn.ToString( "d MMMM, yyyy" );

            this.lblServiceMemberUnitAndBranch.Text = String.Format(
                "{0}, {1}",
                this.UnitAssignmentFrom( serviceMember ),
                this.BranchFrom( serviceMember ) );

            this.lblServiceMemberCurrentAddress.Text = serviceMember.CurrentAddress.AsPostalLabelUsing( " " );
            this.lblServiceMemberPermanentAddress.Text = serviceMember.HomeOfRecord.AsPostalLabelUsing( " " );
            this.lblPrimaryPhoneNumber.Text = serviceMember.PrimaryPhoneNumber.AsUSString();
            this.lblSecondaryPhoneNumber.Text = serviceMember.SecondaryPhoneNumber.AsUSString();
        }
        #endregion

        #region Methods
        #endregion

        #region Properties
        #endregion

        #region Private Methods
        private string BranchFrom( ServiceMember serviceMember )
        {
            if( serviceMember.Branch != null )
            {
                return serviceMember.Branch.DisplayString;
            }
            return String.Empty;
        }

        private string UnitAssignmentFrom( ServiceMember serviceMember )
        {
            if( serviceMember.UnitAssignment != null )
            {
                return serviceMember.UnitAssignment.Name;
            }
            return String.Empty;
        }
        #endregion

        #region Private Properties
        private ServiceMember ServiceMember
        {
            get
            {
                return (ServiceMember)this.Model;
            }
        }
        #endregion

        #region Construction and Finalization
        #endregion

        #region Data Elements
        #endregion
    }
}
